package com.example.laixunlong.control;

import static com.example.laixunlong.control.Spinner_xiala.icon;
import static com.example.laixunlong.control.Spinner_xiala.table;
import static com.example.laixunlong.control.Spinner_xiala.value;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.Toast;

import com.example.laixunlong.R;

import java.util.ArrayList;
import java.util.List;

public class ListView_biaodan extends AppCompatActivity {

    ListView list;
    CheckBox box1;
    CheckBox box2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view_biaodan);
        list=findViewById(R.id.list_table_1);
        box1=findViewById(R.id.list_check_1);
        box2=findViewById(R.id.list_check_2);
        //适配器3:通过继承BaseAdapter,创建自定义条目内容,详细的设置在下文内部类中,四个抽象方法的重写
        custom_tiaomu custom;
        List<structure> l=new ArrayList<>();
        for(int i=0;i<table.length;i++)
        {
            structure s=new structure(table[i],value[i],icon[i]);
            l.add(s);
        }
        custom=new custom_tiaomu(this,l);
        Log.e("数据大小:",l.size()+"");
        list.setAdapter(custom);//往表单布局中,添加适配器

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override/*此事件为点击某一项事件,必须设置内容,否则页面将不显示*/
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                /*使用参数position作为下标进行内容获取*/
                String a=table[position];
                Toast.makeText(ListView_biaodan.this,"你选中:"+a,Toast.LENGTH_SHORT).show();
            }
        });


        box1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override/*选中显示分割线事件*/
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(box1.isChecked())
                {   Drawable drawable=getResources().getDrawable(R.color.color_4A4A4A,getTheme());
                    list.setDivider(drawable);
                    list.setDividerHeight(10);}
                else
                {   list.setDivider(null);
                    list.setDividerHeight(0);}
            }
        });
        box2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override/*选中显示按压背景事件*/
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(box2.isChecked())
                {Drawable drawable=getResources().getDrawable(R.color.color_4A4A4A,getTheme());
                    list.setSelector(R.color.yellow_select);}
                else
                {list.setSelector(getResources().getDrawable(R.color.color_00000000,getTheme()));}

            }
        });

    }
}